package net.techwatch.jpa.entity;

import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

@Entity
public class Department {

	private long id;
	private String department;
	private Employee headDepartment;
	private Employee manager;
	private long budget;
	private String location;
	private String phoneNumber;
	private Set<Employee> members;
	
	public Department() {
		// nothing to do
	}

	/**
	 * @return the id
	 */
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="DEPARTMENT_ID", nullable=false)
	public long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	private void setId(long id) {
		this.id = id;
	}

	/**
	 * @return the department
	 */
	@Basic(optional=false)
	public String getDepartment() {
		return department;
	}

	/**
	 * @param department the department to set
	 */
	public void setDepartment(String department) {
		this.department = department;
	}

	/**
	 * @return the headDepartment
	 */
	@OneToOne
	@JoinColumn(name="HEAD_DEPARTMENT", nullable=false, referencedColumnName="PERSON_ID")
	public Employee getHeadDepartment() {
		return headDepartment;
	}

	/**
	 * @param headDepartment the headDepartment to set
	 */
	public void setHeadDepartment(Employee headDepartment) {
		this.headDepartment = headDepartment;
	}

	/**
	 * @return the managerNumber
	 */
	@OneToOne
	@JoinColumn(name="MANAGER", nullable=false, referencedColumnName="PERSON_ID")
	public Employee getManager() {
		return manager;
	}

	/**
	 * @param managerNumber the managerNumber to set
	 */
	public void setManager(Employee manager) {
		this.manager = manager;
	}

	/**
	 * @return the budget
	 */
	@Basic(optional=false)
	public long getBudget() {
		return budget;
	}

	/**
	 * @param budget the budget to set
	 */
	public void setBudget(long budget) {
		this.budget = budget;
	}

	/**
	 * @return the location
	 */
	@Basic(optional=false)
	public String getLocation() {
		return location;
	}

	/**
	 * @param location the location to set
	 */
	public void setLocation(String location) {
		this.location = location;
	}

	/**
	 * @return the phoneNumber
	 */
	@Column(name="PHONE_NUMBER", nullable=false)
	public String getPhoneNumber() {
		return phoneNumber;
	}

	/**
	 * @param phoneNumber the phoneNumber to set
	 */
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	/**
	 * @return the members
	 */
	@OneToMany(cascade=CascadeType.PERSIST, fetch=FetchType.LAZY, mappedBy="department")
	public Set<Employee> getMembers() {
		return members;
	}

	/**
	 * @param members the members to set
	 */
	public void setMembers(Set<Employee> members) {
		this.members = members;
	}
}
